﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using LinqToLdap;

namespace LINQtoLDAPDemo_Model
{
    // TODO: Look into connection pooling
    class ConfiguredDirectoryContext
    {
        private static LdapConfiguration _configuration;

        private ConfiguredDirectoryContext()
        {
            _configuration = new LinqToLdap.LdapConfiguration();
            _configuration.ConfigureFactory(ConfigurationManager.AppSettings["computerName"]);
            //_configuration.ConfigurePooledFactory(ConfigurationManager.AppSettings["computerName"]).MaxPoolSizeIs(1);
            _configuration.AddMapping(new UserMapping());
            _configuration.AddMapping(new GroupMapping());
            _configuration.UseStaticStorage();
        }

        public static DirectoryContext DirectoryContext
        {
            get
            {
                if (_configuration == null)
                    new ConfiguredDirectoryContext();

                return new DirectoryContext();
            }
        }
    }
}
